#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1, end2 = num2.size() - 1;
        std::string num3;
        int carry = 0;
        while (end1 >= 0 || end2 >= 0)
        {
            int val1 = end1 >= 0 ? num1[end1] - '0' : 0;
            int val2 = end2 >= 0 ? num2[end2] - '0' : 0;
            int car = carry;
            carry = (val1 + val2 + car) / 10;
            num3 += ((val1 + val2 + car) % 10) + '0';
            end1--;
            end2--;
        }
        if (carry == 1)
        {
            num3 += '1';
        }
        reverse(num3.begin(), num3.end());
        return num3;
    }
};